<?php
class PanelFilterRequest extends PageElement
{

	protected $showDeleted = false;
	protected $showAfter = false;
	protected $showBefore = false;
	protected $showLocations = false;
	protected $showEventTypes = false;

	public function showDeleted($showDeleted)
	{
		$this->showDeleted = $showDeleted;
	}

	public function showBefore($showBefore)
	{
		$this->showBefore = $showBefore;
	}

	public function showAfter($showAfter)
	{
		$this->showAfter = $showAfter;
	}

	public function showLocations($showLocations)
	{
		$this->showLocations = $showLocations;
	}

	public function showEventInvolvees($showEventInvolvees)
	{
		$this->showEventInvolvees = $showEventInvolvees;
	}

	public function showEventTypes($showEventTypes)
	{
		$this->showEventTypes = $showEventTypes;
	}


	public function getHTML()
	{

		$html = "<table>\n";

		$Checkbox = new Checkbox();
		$Checkbox->setName("ShowDeleted");
		$Checkbox->setText("Show deleted");
		$Checkbox->setChecked($this->showDeleted);
		$html .= "<tr><td>".$Checkbox->getHTML()."</td><td></td></tr>";

		$Checkbox = new Checkbox();
		$Checkbox->setName("ShowBefore");
		$Checkbox->setText("Show before");
		$Checkbox->setChecked($this->showBefore);

		$input = new DateSelect();
		$input->setName("dtShowBefore");
		$input->setDate("now");
		$html .= "<tr><td>".$Checkbox->getHTML()."</td><td>".$input->getHTML()."</td></tr>";

		$Checkbox = new Checkbox();
		$Checkbox->setName("ShowAfter");
		$Checkbox->setText("Show after");
		$Checkbox->setChecked($this->showAfter);

		$input = new DateSelect();
		$input->setName("dtShowAfter");
		$input->setDate("now");
		$html .= "<tr><td>".$Checkbox->getHTML()."</td><td>".$input->getHTML()."</td></tr>";

// Event Types
		$Checkbox = new Checkbox();
		$Checkbox->setName("ShowEventTypes");
		$Checkbox->setText("Show Event type");
		$Checkbox->setChecked($this->showEventTypes);

		$enumeration = new Enumeration($this->parentPage->getDatabase()->Recopy(),'EventTypes');
		$anArray = $enumeration->getArray();
		$input = new DropDownListEnumeration($anArray);
		if(isset($_POST['dtEventType']))
			$input->setSelectedValue($_POST['dtEventType']);
		$input->setName("dtEventType");
/*		if($this->RecordID != -1)
			$input->setValue($row[$key]);*/
		$html .= "<tr><td>".$Checkbox->getHTML()."</td><td>".$input->getHTML()."</td></tr>";

// Locations
		$Checkbox = new Checkbox();
		$Checkbox->setName("ShowLocations");
		$Checkbox->setText("Show locations");
		$Checkbox->setChecked($this->showLocations);

		$sql = "select LocationNameID, LongName from LocationNames";
		$anArray = array();
		$database = $this->parentPage->getDatabase()->Recopy();
		$database->ExecuteSQL($sql);
		while($row1 = $database->getRow())
		{
			$anArray[$row1['LocationNameID']] = $row1['LongName'];
		}
		$input = new MultiSelectEnumeration($anArray);
		$input->setName('dtLocation');
		$input->setSize(count($anArray));
		if(isset($_POST['dtLocation']))
			$input->setSelected($_POST['dtLocation']);
		$html .= "<tr><td>".$Checkbox->getHTML()."</td><td>".$input->getHTML()."</td></tr>";

// Involvees
		$Checkbox = new Checkbox();
		$Checkbox->setName("ShowEventInvolvees");
		$Checkbox->setText("Show those involved");
		$Checkbox->setChecked($this->showEventInvolvees);
		$sql = "select EventInvolveeNameID, LongName from EventInvolveeNames";
		$anArray = array();
		$database = $this->parentPage->getDatabase()->Recopy();
		$database->ExecuteSQL($sql);
		while($row1 = $database->getRow())
		{
			$anArray[$row1['EventInvolveeNameID']] = $row1['LongName'];
		}
		$input = new MultiSelectEnumeration($anArray);
		$input->setName('dtEventInvolvee');
		$input->setSize(count($anArray));
		if(isset($_POST['dtEventInvolvee']))
			$input->setSelected($_POST['dtEventInvolvee']);
		$html .= "<tr><td>".$Checkbox->getHTML()."</td><td>".$input->getHTML()."</td></tr>";



		$refreshButton = new Button();
		$refreshButton->setName("refreshButton");
		$refreshButton->setValue("Refresh");
		$refreshButton->setOnClick("EventsRefresh();");
		$html .= "<tr><td>".$refreshButton->getHTML()."</td><td></td></tr>";

		$html .= "</table>\n";
		
		return $html;
	}
}
